package com.spongeli.user.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Service;

import com.spongeli.entity.AlipayAdmin;
import com.spongeli.entity.AlipayAdminExample;
import com.spongeli.user.entity.User;
import com.spongeli.user.mapper.AlipayAdminMapper;
import com.spongeli.user.service.IUserService;
import com.spongeli.user.util.ExcelUtil;
import com.spongeli.user.util.MapEntry;

@Service("userServiceImpl")
public class UserServiceImpl implements IUserService {

	/*@Resource
	private UserMapper userMapper;*/
	
	@Resource
	private AlipayAdminMapper alipayAdminMapper;
	
	public List<User> getallUser() {
		Map<String,Object> con = new HashMap<String,Object>();
		con.put("pwd", "123");
		con.put("abc", "1");
		return null;/*userMapper.getallUser(con);*/
	}

	@Override
	public void downLoad(HttpServletResponse  response) {
		AlipayAdminExample example = new AlipayAdminExample();
		List<AlipayAdmin> list = alipayAdminMapper.selectByExample(example);
		AlipayAdmin admin = new AlipayAdmin();
		
		List<MapEntry<String, Object>> sheetHeader = new ArrayList<>();
		MapEntry<String, Object> e = new MapEntry<>();
		e.setKey("id");
		e.setValue("编号");
		MapEntry<String, Object> e1 = new MapEntry<>();
		e1.setKey("adminName");
		e1.setValue("用户名");
		MapEntry<String, Object> e2 = new MapEntry<>();
		e2.setKey("adminPwd");
		e2.setValue("密码");
		MapEntry<String, Object> e3 = new MapEntry<>();
		e3.setKey("status");
		e3.setValue("状态");
		MapEntry<String, Object> e4 = new MapEntry<>();
		e4.setKey("lastLoginTime");
		e4.setValue("上次登录时间");
		MapEntry<String, Object> e5 = new MapEntry<>();
		e5.setKey("createTime");
		e5.setValue("创建时间");
		MapEntry<String, Object> e6 = new MapEntry<>();
		e6.setKey("updateTime");
		e6.setValue("更新时间");
		sheetHeader.add(e);
		sheetHeader.add(e1);
		sheetHeader.add(e2);
		sheetHeader.add(e3);
		sheetHeader.add(e4);
		sheetHeader.add(e5);
		sheetHeader.add(e6);
		
		
		List<Map<String, Object>> data = new ArrayList<>();
		
		if(list != null && list.size() > 0){
			for (Iterator<AlipayAdmin> iterator = list.iterator(); iterator.hasNext();) {
				AlipayAdmin admin1 = (AlipayAdmin)iterator.next();
				Map<String,Object> map2 = new HashMap<>();
				map2.put("id", admin1.getId());
				map2.put("adminName", admin1.getAdminName());
				map2.put("adminPwd", admin1.getAdminPwd());
				map2.put("status", admin1.getStatus());
				map2.put("lastLoginTime", admin1.getLastLoginTime());
				map2.put("createTime", admin1.getCreateTime());
				map2.put("updateTime", admin1.getUpdateTime());
				data.add(map2);
			}
			
		}
		ExcelUtil.getWorkBook(1000, "用户", "用户" ,sheetHeader, data,response);
	}

}
